/**
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/

#ifndef ASCENDC_MODULE_SIMT_MATH_INTERFACE_IMPL_H
#define ASCENDC_MODULE_SIMT_MATH_INTERFACE_IMPL_H

#include "kernel_simt_common_intf_impl.h"

namespace AscendC {
namespace Simt {
template <typename T>
__aicore__ inline T Abs(T x)
{
    static_assert(SupportType<T, int32_t, int64_t, half, float>(), "Input type only supports int32_t, int64_t, half, float.");
    return AbsImpl(x);
}

template <typename T>
__aicore__ inline T UintDiv(T dividend, T magic, T shift)
{
    static_assert(SupportType<T, uint32_t, uint64_t>(), "Input type T only supports uint32_t, uint64_t.");
    return UintDivImpl(dividend, magic, shift);
}

template <typename T>
__aicore__ inline T Fma(T x, T y, T z)
{
    static_assert(SupportType<T, half, float>(), "Input type only supports half, float.");
    return FmaImpl(x, y, z);
}

template <typename T>
__aicore__ inline T Max(T x, T y)
{
    static_assert(
        SupportType<T, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, half, float>(),
        "Input type only supports int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, half, float.");
    return MaxImpl(x, y);
}

template <typename T>
__aicore__ inline T Min(T x, T y)
{
    static_assert(
    SupportType<T, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, half, float>(),
    "Input type only supports int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, half, float.");
    return MinImpl(x, y);
}

template <typename T>
__aicore__ inline T Fdim(T x, T y)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    return DimImpl(x, y);
}

template <typename T, typename U>
__aicore__ inline T RemQuo(T x, T y, U *quo)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    static_assert(SupportType<U, int32_t>(), "Input type U only supports int32_t.");
    return RemQuoImpl(x, y, quo);
}

template <typename T>
__aicore__ inline T Mod(T x, T y)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    return ModImpl(x, y);
}

template <typename T>
__aicore__ inline T Remainder(T x, T y)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    return RemainderImpl(x, y);
}

template <typename T>
__aicore__ inline T CopySign(T x, T y)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    return CopySignImpl(x, y);
}

template <typename T>
__aicore__ inline T NearbyInt(T x)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    return NearByIntImpl(x);
}

template <typename T>
__aicore__ inline T NextAfter(T x, T y)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    return NextAfterImpl(x, y);
}

template <typename T, typename U>
__aicore__ inline T ScaLbn(T x, U n)
{
    static_assert(SupportType<T, float>(), "Input type T only supports float.");
    static_assert(SupportType<U, int32_t, int64_t>(), "Input type U only supports int32_t, int64_t.");
    return ScaLbnImpl(x, n);
}

template <typename T>
__aicore__ inline T Brev(T x)
{
    static_assert(SupportType<T, uint32_t, uint64_t>(), "Input type T only supports uint32_t, uint64_t.");
    return BrevImpl(x);
}

// count the leading zero bits
template <typename T>
__aicore__ inline int32_t Clz(T x)
{
    static_assert(SupportType<T, int32_t, int64_t, uint32_t, uint64_t>(),
        "Input type of Clz function only supports int32_t, uint32_t, int64_t, uint64_t.");
    return ClzImpl(x);
}

// count the number of set 1 bit
template <typename T>
__aicore__ inline int32_t Popc(T x)
{
    static_assert(SupportType<T, uint32_t, uint64_t>(), "Input type T only supports uint32_t, uint64_t.");
    return PopcImpl(x);
}

template <typename T>
__aicore__ inline T BytePerm(T x, T y, T s)
{
    static_assert(SupportType<T, uint32_t>(), "Input type T only supports uint32_t.");
    return BytePermImpl(x, y, s);
}

template <typename T>
__aicore__ inline int32_t Ffs(T x)
{
    static_assert(SupportType<T, int32_t, int64_t>(), "Input type T only supports int32_t, int64_t.");
    return FfsImpl(x);
}

template <typename T>
__aicore__ inline T MulHi(T x, T y)
{
    static_assert(SupportType<T, int32_t, uint32_t>(), "Input type T only supports int32_t, uint32_t.");
    return MulHiImpl(x, y);
}
}  // namespace Simt
}  // namespace AscendC
#endif  // ASCENDC_MODULE_SIMT_MATH_INTERFACE_IMPL_H
